//
//  LaunchScrollView.m
//  JWMovie
//
//  Created by Jorn.Wu on 15/7/27.
//  Copyright (c) 2015年 Jorn.Wu. All rights reserved.
//

#import "LaunchScrollView.h"
#import "LaunchScrollViewCell.h"
#import "constant.h"

@interface LaunchScrollView ()

@property (nonatomic, strong) NSMutableArray *bgImageAr;
@property (nonatomic, strong) NSMutableArray *pgImageAr;

@end

@implementation LaunchScrollView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.delegate = self;
        self.pagingEnabled = YES;
        self.bounces = NO;
        
        [self loadImages];
        [self addLaunchScrollViewCell];
        
    }
    return self;
}

- (void)loadImages{
    _bgImageAr = [NSMutableArray array];
    _pgImageAr = [NSMutableArray array];
    
    for (int i = 0; i < 5; i++) {
        NSString *str1 = [NSString stringWithFormat:@"guide%d@2x",i + 1];
        [_bgImageAr addObject:str1];
        
        NSString *str2 = [NSString stringWithFormat:@"guideProgress%d@2x",i + 1];
        [_pgImageAr addObject:str2];
        
    }
    
}

- (void)addLaunchScrollViewCell{
    self.contentSize = CGSizeMake(JWScreenWidth * _bgImageAr.count, JWScreenHeight);
    for (int i = 0; i < _bgImageAr.count; i ++) {
        
        LaunchScrollViewCell *viewCell = [[LaunchScrollViewCell alloc] initWithFrame:CGRectMake(JWScreenWidth * i, 0, JWScreenWidth, JWScreenHeight)];
        [viewCell setImageWithbgImageName:self.bgImageAr[i] pageImageName:self.pgImageAr[i]];
        
        if (i == _bgImageAr.count - 1) {
            viewCell.enterBtn.hidden = NO;
            [viewCell.enterBtn addTarget:self action:@selector(enterBtnAction) forControlEvents:UIControlEventTouchUpInside];
            [viewCell.enterBtn showsTouchWhenHighlighted];
        }
        
        [self addSubview:viewCell];
        
    }
}

- (void)enterBtnAction{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"clickEnterBtn" object:nil userInfo:nil];
}













/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
